package com.karina.visualization.chart.skins;

import com.karina.visualization.chart.client.Graphics;
import com.karina.visualization.chart.model.YAxisModel;

public class YAxisSkin extends BaseSkin<YAxisModel> {

	private YAxisModel data;

	private final int NUM = 5;

	@Override
	public void setData(YAxisModel data) {
		this.data = data;
	}

	@Override
	public YAxisModel getData() {
		return data;
	}

	@Override
	public void draw(Graphics graphics) {
		drawLine(graphics);
		drawCategoryPoint(graphics);
		drawText(graphics);
	}

	private void drawCategoryPoint(Graphics graphics) {

		int value = (int) data.getMaxValue();
		int height = (int) (data.getHeight() - data.getTextMargin());
		int x = (int) (data.getX() + data.getTextMargin());
		int y = data.getY();

		int markPoint = y;
		int gap = height / NUM;
		int vGap = (value / NUM);
		String message = "" + value;
		graphics.saveContext();
		graphics.beginPath();
		setStyle(graphics);
		for (int i = 0; i < NUM; i++) {
			graphics.moveTo(x, markPoint).lineTo(x + 5, markPoint);
			graphics.drawText(x - 5, markPoint, message, "right", "middle");
			value -= vGap;
			message = "" + value;
			markPoint += gap;
		}

		graphics.stroke();
		graphics.endPath();
		graphics.restoreContext();
	}

	private void drawText(Graphics graphics) {

	}

	private void drawLine(Graphics graphics) {
		int height = (int) (data.getHeight() - data.getTextMargin());
		int x = (int) (data.getX() + data.getTextMargin());
		int y = data.getY();

		graphics.saveContext();
		setStyle(graphics);
		graphics.beginPath();
		graphics.moveTo(x, y);
		graphics.lineTo(x, y + height);
		graphics.stroke();
		graphics.endPath();
		graphics.restoreContext();
	}

	@Override
	public void cleanup(Graphics graphics) {
		// TODO Auto-generated method stub

	}

	@Override
	public void refresh(Graphics graphics) {
		// TODO Auto-generated method stub

	}

}
